<template>
  <div class="complete-user-info">
    <h2>完善用户信息</h2>
    <div class="form">
      <el-form ref="form" :model="form" label-width="120px" size="small" :rules="rules">
        <el-form-item label="密保问题:" prop="question">
          <el-select v-model="form.question" style="width:230px">
            <el-option value="1" label="你的小学班主任姓名?"></el-option>
            <el-option value="2" label="你的初中班主任姓名?"></el-option>
            <el-option value="3" label="你的高中班主任姓名?"></el-option>
            <el-option value="4" label="你的喜欢的运动?"></el-option>
            <el-option value="5" label="你的喜欢的食物?"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="答案:" prop="answer">
          <el-input v-model="form.answer" placeholder="请输入答案" style="width:230px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="background:#ff8b00;color:#fff" @click="onSubmit">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "completeUserInfo",
  data() {
    return {
      form: {
        question: "",
        answer: "",
      },
      rules: {
        question: [{ required: true, message: "不能为空", trigger: "blur" }],
        answer: [{ required: true, message: "不能为空", trigger: "blur" }]
      }
    };
  },
  methods: {
    onSubmit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(this.form);
          let params = {
            passwordProtection: [{
              securityAnswer: this.form.question,
              securityQuestion: this.form.answer
            }]
          };
          this.$api.common.setPasswordProtection(params)
            .then((res) => {
              this.$message.success("设置成功");
              this.$store.state.isSecuritySettings=1;
              this.$router.push("/home");
            });
        }
      });
    }
  },
};
</script>

<style lang="scss">
.complete-user-info {
  h2 {
    height: 50px;
    border-bottom: 1px solid #e1e1e1;
    line-height: 50px;
    font-weight: normal;
    padding-left: 30px;
    font-size: 20px;
  }

  .form {
    max-width: 700px;
    margin: 30px 0px;
  }
}
</style>
